package com.longcai.piaojia.adapter;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.longcai.piaojia.R;
import com.longcai.piaojia.conn.ChooseGoodsListGet;
import com.longcai.piaojia.conn.LatestOrderTimeGet;
import com.zcx.helper.bound.BoundView;
import com.zcx.helper.bound.BoundViewHelper;
import com.zcx.helper.scale.ScaleScreenHelperFactory;

import java.util.List;

/**
 * Created by Administrator on 2017/1/9.
 */
public class LatestOrderDateadapter extends ArrayAdapter<LatestOrderTimeGet.OrderDateEntity> {

    private Context context;
    private LayoutInflater layoutInflater;
    public int selPosition = -1;

    public LatestOrderDateadapter(Context context, List<LatestOrderTimeGet.OrderDateEntity> dateLists) {

        super(context, 0, dateLists);

        this.context = context;

        this.layoutInflater = LayoutInflater.from(context);
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {

        LatestOrderTimeGet.OrderDateEntity orderDateEntity = getItem(position);

        ViewHolder viewHolder;

        if (convertView == null) {

            convertView = BoundViewHelper.boundView(viewHolder = new ViewHolder(), ScaleScreenHelperFactory.getInstance().loadView((ViewGroup) layoutInflater.inflate(R.layout.item_latest_choose_time_grid, null)));

            convertView.setTag(viewHolder);

        } else {

            viewHolder = (ViewHolder) convertView.getTag();

        }


        if (position == selPosition){

            viewHolder.item_choose_goods_ll.setBackgroundResource(R.drawable.item_latest_choose_time_sel_bg);
            viewHolder.item_choose_goods_time_tv.setTextColor(ContextCompat.getColor(context, R.color.white));
            viewHolder.item_choose_goods_date_tv.setTextColor(ContextCompat.getColor(context, R.color.white));

        } else if (orderDateEntity.stock.equals("0")) {

            viewHolder.item_choose_goods_ll.setBackgroundResource(R.drawable.item_latest_choose_time_sel_grey_bg);
            viewHolder.item_choose_goods_time_tv.setTextColor(ContextCompat.getColor(context, R.color.white));
            viewHolder.item_choose_goods_date_tv.setTextColor(ContextCompat.getColor(context, R.color.white));

        }else{

            viewHolder.item_choose_goods_ll.setBackgroundResource(R.drawable.item_latest_choose_time_no_bg);
            viewHolder.item_choose_goods_time_tv.setTextColor(ContextCompat.getColor(context, R.color.text_color));
            viewHolder.item_choose_goods_date_tv.setTextColor(ContextCompat.getColor(context, R.color.text_color));
        }


        viewHolder.item_choose_goods_time_tv.setText(orderDateEntity.time_tip);
        viewHolder.item_choose_goods_date_tv.setText(orderDateEntity.starttime + "-" + orderDateEntity.endtime);

        Log.e("---", orderDateEntity.time_tip + orderDateEntity.starttime + "-1" + orderDateEntity.endtime);

        return convertView;
    }

    class ViewHolder {

        @BoundView(R.id.item_choose_goods_ll) public LinearLayout item_choose_goods_ll;
        @BoundView(R.id.item_choose_goods_time_tv) public TextView item_choose_goods_time_tv;
        @BoundView(R.id.item_choose_goods_date_tv) public TextView item_choose_goods_date_tv;

    }
}
